package br.edu.fafica.login;

import java.io.IOException;
//import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
//import javax.servlet.UnavailableException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Login
 */
@WebServlet("/LoginServelet")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public Login() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ServletContext loge = getServletContext();
		String login = loge.getInitParameter("Login");
		String senha = loge.getInitParameter("Senha");
		String msg = "falso";

		String loginUsuario = request.getParameter("login");
		String senhaUsuario = request.getParameter("senha");

		if (!(login.equals(loginUsuario) && senha.equals(senhaUsuario))) {
			// throw new UnavailableException("Login e senha incorretos");
			msg = "verdade";
			request.setAttribute("msg", msg);
			response.sendRedirect("menu.html");
		} else {
			msg = "falso";
			request.setAttribute("msg", msg);
			response.sendRedirect("Login.jsp");
		}

	}

}
